package com.zhangmin.com.aiit.test;

public class sss {
    public static void replaceSpace(StringBuffer str) {
    /*请实现一个函数，将一个字符串中的每个空格替换成“%20”。例如，当字符串为We Are Happy.
        则经过替换之后的字符串为We%20Are%20Happy。
     */
        String str1 = str.toString();
        char[] arrs = str1.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (char s : arrs) {
             if(s ==' '){
                   sb.append("%20");
             }else{
                 sb.append(s);
             }
        }

//         String string=sb.toString();
         System.out.println(sb.toString());

    }

    public static void main(String[] args) {
        StringBuffer str2 = new StringBuffer("we are happy");
          replaceSpace(str2);

    }
}
